package com.hdd.hll.modules.order.web;

import com.hdd.hll.common.response.Response;
import com.hdd.hll.common.response.ResponseUtils;
import com.hdd.hll.common.utils.StringUtils;
import com.hdd.hll.modules.order.bean.PlanOrder;
import com.hdd.hll.modules.order.bean.PlanOrderAll;
import com.hdd.hll.modules.order.service.PlanService;
import com.hdd.hll.modules.order.web.dto.AddPlandDto;
import com.hdd.hll.modules.order.web.dto.PlanDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/plan")
@Slf4j
@Api(value="调拨单",tags={"调拨单"})
public class PlanController {

    @Autowired
    PlanService planService;

    @ApiOperation(value="调拨单添加", notes="注意别出错" ,httpMethod="POST")
    @RequestMapping(value="/addPlans", method= RequestMethod.POST)
    public Response<Integer> addPlans(@RequestBody AddPlandDto dto){
        log.info("调拨单添加-请求参数：,{}",dto);
        return  planService.addPlans(dto);
    }


    @ApiOperation(value="全部调拨单数据查询包括京东调拨单", notes="注意别出错" ,httpMethod="GET")
    @RequestMapping(value="/findPlans", method= RequestMethod.GET)
    public Response<List<PlanOrderAll>> findPlans(){
        List<PlanOrderAll> plans = planService.findPlans();
        log.info("调拨单查询-返回参数：,{}",plans);
        return ResponseUtils.inits(plans);
    }


    @ApiOperation(value="调拨单条件查询", notes="注意别出错" ,httpMethod="POST")
    @RequestMapping(value="/findPlans", method= RequestMethod.POST)
    public Response<List<PlanOrder>> findPlans(@RequestBody PlanDto dto){
        log.info("调拨单条件查询-请求参数：,{}",dto);
        if(StringUtils.isNullOrEmpty(dto)){
            return ResponseUtils.initsByCode("common.param.empty");
        }
        if(dto.getDataSize()>10000){
            return ResponseUtils.initsByCode("common.data.large");
        }
        if(dto.getDataSize()<=0){
            return ResponseUtils.initsByCode("common.data.small");
        }

        List<PlanOrder> plans = planService.findPlans(dto);
        log.info("调拨单条件查询-返回参数：,{}",plans);
        return ResponseUtils.inits(plans);
    }

}
